package com.risk.kernel.utils;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author: Liwen
 * @createTime: 2024/11/25
 * @description:
 */
public class DateUtil {

    /**
     * 计算耗时
     * @param startZdt
     * @param endZdt
     * @return
     */
    public static String getTimeConsuming(ZonedDateTime startZdt, ZonedDateTime endZdt) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String startTime = formatter.format(startZdt);
        String endTime = formatter.format(endZdt);
        LocalDateTime dateTime1Obj = LocalDateTime.parse(startTime, formatter);
        LocalDateTime dateTime2Obj = LocalDateTime.parse(endTime, formatter);
        Duration duration = Duration.between(dateTime1Obj, dateTime2Obj);
        long totalSeconds = duration.getSeconds();
        long minutes = (totalSeconds % 3600) / 60;
        long seconds = totalSeconds % 60;
        return minutes + "分" + seconds + "秒";
    }

    public static String getCurrentDateTime(){
        LocalDateTime dateTime = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return dateTime.format(formatter);
    }
    public static String getCurrentDateTimeNumbers(){
        LocalDateTime dateTime = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss");
        return dateTime.format(formatter);
    }
}
